
import React, { Component } from "react";
import {viewModel} from 'nc-lightapp-front';
let { getGlobalStorage } = viewModel;
/**
 * 行选中逻辑处理
 * @param {*} Table
 */
export default function hoverContent(Table) {
    return class MetaTable extends Component {
        constructor(props) {
            super(props);
            this.nccTable = JSON.parse(getGlobalStorage('localStorage', 'nccTable')) || {};
            this.ncc_automated=getGlobalStorage('localStorage',"_ncc_automated_");
        }

        render() {
            let {
                columns,
                totalColumns,
                hoverContent = true, // true
                ...others
            } = this.props;

            let oprColumn = null;
            if (this.ncc_automated === '1' || this.nccTable.rowcheckedButton !== 'suspension') {
                hoverContent=false;
            }
            if (hoverContent) {
                // 浅拷贝一下，避免出问题
                columns = [...columns];
                let last;
                columns.forEach((item, index) => {
                    if (
                        (item.attrcode === "opr" || item.attrcode === 'operate') &&
                        // item.itemtype === "customer" &&
                        item.render
                    ) {
                        oprColumn = item;
                        columns.splice(index, 1);
                        totalColumns && totalColumns.splice(index, 1);
                    } else {
                        item.visible && (last = item);
                    }
                });
                // 识别最后一列  加个样式
                last && (last.className += ' table-last-column ');
                last && totalColumns && (totalColumns[totalColumns.length - 1].className += ' table-last-column ');
            }

            return (
                <Table
                    columns={columns}
                    totalColumns={totalColumns}
                    hoverContent={
                        oprColumn && hoverContent
                            ? (record, index) => {
                                if(!record||index<0){return null;}
                                return (
                                    <div className="hover-content">
                                        {record ? oprColumn.render("", record, index) : ""}
                                    </div>
                                );
                            }
                            : undefined
                    }
                    {...others}
                />
            );
        }
    };
}
